package app.caretrack.model;

import java.io.Serializable;
import java.util.ArrayList;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name = "LogId")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class LogId implements Serializable {

    private static final long serialVersionUID = 1L;
    /**
     * Identifier for this row.
     */
    private int id;
    /**
     * Which LogData this set of values belongs to Needed to prevent a join
     * table.
     */
    private LogData logData;

    /**
     * Identifies the Log ID, what type of values are stored in the valueList.
     */
    private int logId;
    /**
     * Which MID the values come from.
     */
    private int mid;

    private ArrayList<Long> valueList;

    /**
     * @return Return the row identifier
     */
    @Id
    @SequenceGenerator(name = "LOGDATA_SEQ", sequenceName = "LOGDATA_SEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "LOGDATA_SEQ")
    public int getId() {
        return this.id;
    }

    /**
     * @param id The identifier
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return Returns the logId.
     */
    public int getLogId() {
        return this.logId;
    }

    /**
     * @param logId The logId to set.
     */
    public void setLogId(int logId) {
        this.logId = logId;
    }

    /**
     * Set length to 2000 since default is RAW(255)
     * 
     * @return Returns the values.
     */
    @Column(length = 10000)
    public ArrayList<Long> getValueList() {
        return this.valueList;
    }

    /**
     * @param valueList The values to set.
     */
    public void setValueList(ArrayList<Long> valueList) {
        this.valueList = valueList;
    }

    /**
     * @return Returns the logData.
     */
    @ManyToOne(optional = false, cascade = CascadeType.REMOVE)
    public LogData getLogData() {
        return this.logData;
    }

    /**
     * @param logData The logData to set.
     */
    public void setLogData(LogData logData) {
        this.logData = logData;
    }

    @Override
    public String toString() {
        StringBuilder str = new StringBuilder();
        str.append("Id: " + this.id + ", ");
        str.append("LogId: " + this.logId + ", ");
        str.append("Values: " + this.valueList);

        return str.toString();
    }

    /**
     * @returns true if o is a LogID with the same logID as this LogID
     */
    @Override
    public boolean equals(Object o) {
        if (o instanceof LogId) {
            LogId l = (LogId) o;
            return l.getLogId() == getLogId();
        } else {
            return false;
        }
    }

    /**
     * @return Returns the mid.
     */
    public int getMid() {
        return this.mid;
    }

    /**
     * @param mid The mid to set.
     */
    public void setMid(int mid) {
        this.mid = mid;
    }

}
